package org.filetransfer.file_transfer_java_backend.utils;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.filetransfer.file_transfer_java_backend.service.StatService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;
@Component
public class StatisticVisitInterceptor implements HandlerInterceptor {

    @Autowired
    private StatService statService;
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
        String uri = request.getRequestURI();
        if (uri.startsWith("/api/statistic")) {
            statService.recordTodayStat("visit");
        } else if (uri.contains("/api/files")) {
            statService.recordTodayStat("upload");
        } else if (uri.contains("/api/share")) {
            statService.recordTodayStat("download");
        }
        return true;
    }
}
